﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Phone
{
    public partial class Talking : Form
    {
        private int time = 0;

        //默认构造函数
        public Talking()
        {
            InitializeComponent();
        }

        //带参数的构造函数,获取对方号码
        public Talking(string text)
        {
            InitializeComponent();
            label1.Text = text;
        }

        //窗体加载时显示对方号码
        private void Talking_Load(object sender, EventArgs e)
        {
            switch (Vars.busy_sip_or_pstn)
            {
                case "sip":
                    label1.Text = Vars.sip?.GetRemoteUser();
                    break;
                case "pstn1":
                    label1.Text = Vars.pstn1?.GetRemoteUser();
                    break;
                case "pstn2":
                    label1.Text = Vars.pstn2?.GetRemoteUser();
                    break;
            }
            if(label1.Text == "110"||label1.Text=="119"||label1.Text=="120"||label1.Text=="122")button2.Visible = true;
        }

        //挂断
        private void button1_Click(object sender, EventArgs e)
        {
            switch (Vars.busy_sip_or_pstn)
            {
                case "sip":
                    Vars.sip?.UserOptionSelect("Bye");
                    break;
                case "pstn1":
                    Vars.pstn1?.UserOptionSelect("Bye");
                    break;
                case "pstn2":
                    Vars.pstn2?.UserOptionSelect("Bye");
                    break;
            }
        }


        //若开启报警辅助功能并选择发送GPS定位信息，则发送实时定位信息
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (Vars.settings[0] == 1 && Vars.message.Contains("GPS"))
            {
                string message = "实时GPS定位-经度" + Vars.gps.jd.ToString() + "/纬度" + Vars.gps.wd.ToString()+"/高度" + Vars.gps.hb.ToString()+"|"+ Vars.message;
                string remoteMessageNumber = "";
                switch (Vars.busy_sip_or_pstn)
                {
                    case "sip":
                        remoteMessageNumber = Vars.sip.GetRemoteUser();
                        break;
                    case "pstn1":
                        remoteMessageNumber = Vars.pstn1.GetRemoteUser();
                        break;
                    case "pstn2":
                        remoteMessageNumber = Vars.pstn2.GetRemoteUser();
                        break;
                }
                switch (remoteMessageNumber)
                {
                    case "110":
                        remoteMessageNumber = Defines.RECEIVE_MSG_NUMBER_110;
                        break;
                    case "119":
                        remoteMessageNumber = Defines.RECEIVE_MSG_NUMBER_119;
                        break;
                    case "120":
                        remoteMessageNumber = Defines.RECEIVE_MSG_NUMBER_120;
                        break;
                    case "122":
                        remoteMessageNumber = Defines.RECEIVE_MSG_NUMBER_122;
                        break;
                }
                if (Vars.tag== "")return;
                switch (Vars.busy_sip_or_pstn)
                {
                    case "sip":
                        Vars.sip?.SendMsg(remoteMessageNumber, "flag:Tag=" + Vars.tag + ";RealTimeMessage=" + message+";");
                        break;
                    case "pstn1":
                        Vars.pstn1?.SendMsg(remoteMessageNumber, "flag:Tag="+Vars.tag+";RealTimeMessage="+message+";");
                        break;
                    case "pstn2":
                        Vars.pstn2?.SendMsg(remoteMessageNumber, "flag:Tag=" + Vars.tag + ";RealTimeMessage=" + message + ";");
                        break;
                }
            }
            else
            {
                timer2.Enabled = false;
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            time++;
            int hour = time / 3600;
            string hourStr = hour.ToString();
            if (hour < 10)
            {
                hourStr = "0" + hourStr;
            }
            int minute = time / 60 % 60;
            string minuteStr = minute.ToString();
            if (minute < 10)
            {
                minuteStr = "0" + minuteStr;
            }
            int second = time % 60;
            string secondStr = second.ToString();
            if (second < 10)
            {
                secondStr = "0" + secondStr;
            }
            label3.Text = hourStr + ":" + minuteStr + ":" + secondStr;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Text text = new Text();
            text.Show();
            text.Location = this.Location;
            this.Hide();
        }
    }
}
